import { INestApplication } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';

export const setupSwagger = (app: INestApplication): void => {
  const configService: ConfigService = app.get(ConfigService);

  // 默认为启用
  // const enable = configService.get<boolean>('swagger.enable', true);
  const enable = true;
  // 判断是否需要启用
  if (!enable) {
    return;
  }

  // const swaggerConfig = new DocumentBuilder()
  //   .setTitle(configService.get<string>('swagger.title'))
  //   .setDescription(configService.get<string>('swagger.desc'))
  //   // .setLicense('MIT', 'https://github.com/buqiyuan/nest-admin')
  //   .build();

  const options = new DocumentBuilder()
    .setTitle(configService.get('SWAGGER').name)
    .setDescription('测试如何使用nest')
    .setVersion('0.0.1')
    .build();

  const document = SwaggerModule.createDocument(app, options);

  SwaggerModule.setup('/doc', app, document);
};
